package com.qf.web.servlet;

import com.qf.pojo.Emp;
import com.qf.service.EmpService;
import com.qf.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 根据id 查询员工对象， 使用表单进行展示
 *
 *  接收请求
 *  调用service
 *  响应前端
 *
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/selectOneEmp")
public class SelectOneEmpServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {



        String id = req.getParameter("id");

        EmpService service = new EmpServiceImpl();
        //根据id获取员工对象
        Emp emp = service.findById(id);

        //把数据存储到请求域
        req.setAttribute("emp", emp);
        //请求转发  到员工详情页
        req.getRequestDispatcher("/page/empEdit.jsp").forward(req, resp);

    }
}
